<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-02 10:07:38
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-02-19 15:00:16
 * ------------------------------------------------ *
 * 职员模型                                         *
 * ------------------------------------------------ */
namespace Admin\Model;

class AuthsModel extends CommonModel {

	/* 改变状态
	 *--------------------------*/
	public function editStatus(){
	 	if(I('authId',0)==0) return false;
	 	$a = M('auths');
	 	$data['authFlag'] = (I('authFlag')==1)?1:0;
	 	$rs = $a->where("authId=".(int)I('authId',0))->save($data);
	    if(false !== $rs){
			return true;
		}
	 	return false;
	}


	/* 添加权限
	 *--------------------------*/
	 public function addAuths(){
	 	$parentId = I("parentId");
		if($parentId == 0){
			$authpath = '0,';
		}else{
			$rs=M('auths')->field("concat(authPath,authId,',') as authPath")
				->where("authId=".$parentId)->find();
			$authPath = $rs['authPath'];
		}	

		$data = array();
		$data["authIco"] = I("authIco");
		$data["authName"] = I("authName");
		$data["parentId"] = $parentId;
		$data["authPath"] = $authPath;
		$data["controller"] = I("controller");
		$data["action"] = I("action");
		$data["authFlag"] = 1;
	    if($this->checkEmpty($data)){
			$r = M('auths');
			$rs = $r->add($data);
			if(false !== $rs){
				return true;
			}
		}
		return false;
	}

	//删除权限
	 public function delAuths(){
	 	$authId = (int)I('authId');
	 	$a = M('auths');
	 	$data['authFlag']=-1;
	    $rs = $a->where("authId=".$authId)->save($data);
		if(false !== $rs){
			return true;
		}
		return false;
	 }

	 /* 修改权限
	 *--------------------------*/
	 public function editAuths(){
	 	$authId = (int)I("authId",0);
	 	$parentId = I("parentId");
		if($parentId == 0){
			$authpath = '0,';
		}else{
			$rs=M('auths')->field("concat(authPath,authid,',') as authPath")
				->where("authId=".$parentId)->find();
			$authPath = $rs['authPath'];
		}		

		$data = array();
		$data["authIco"] = I("authIco");
		$data["authName"] = I("authName");
		$data["parentId"] = $parentId;
		$data["authPath"] = $authPath;
		$data["controller"] = I("controller");
		$data["action"] = I("action");

	    if($this->checkEmpty($data)){
			$rs = M('auths')->where("authId=".$authId)->save($data);
			if(false !== $rs){
				return true;
			}
		}
		return false;
	}

}
